package com.bytecub.gateway.mq.consume;

import java.util.*;

import com.bytecub.common.domain.dto.response.device.DevicePageResDto;
import com.bytecub.common.enums.BCErrorEnum;
import com.bytecub.common.enums.BatchOpEnum;
import com.bytecub.common.exception.BCGException;
import com.bytecub.gateway.mq.excutor.DeviceMessageUpExecutor;
import com.bytecub.mdm.cache.IMessageCountCache;
import com.bytecub.mdm.cache.IPropertyGetCache;
import com.bytecub.mdm.service.IDeviceService;
import com.bytecub.storage.IMessageReplyService;
import com.bytecub.storage.entity.MessageReplyEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.bytecub.common.biz.EsUtil;
import com.bytecub.common.biz.RedisKeyUtil;
import com.bytecub.common.biz.TopicBiz;
import com.bytecub.common.constants.BCConstants;
import com.bytecub.common.domain.dto.request.ProductFuncItemResDto;
import com.bytecub.common.domain.message.DeviceReportMessage;
import com.bytecub.common.domain.storage.EsMessage;
import com.bytecub.common.metadata.BcMetaType;
import com.bytecub.common.metadata.EsInsertDataBo;
import com.bytecub.common.metadata.ProductFuncTypeEnum;
import com.bytecub.gateway.mq.domain.DeviceUpMessageBo;
import com.bytecub.gateway.mq.storage.DeviceUpMessageStorage;
import com.bytecub.mdm.dao.po.ProductPo;
import com.bytecub.mdm.service.IProductFuncService;
import com.bytecub.mdm.service.IProductService;
import com.bytecub.plugin.redis.CacheTemplate;
import com.bytecub.protocol.base.IBaseProtocol;
import com.bytecub.protocol.service.IProtocolUtilService;
import com.bytecub.storage.IDataCenterService;
import com.bytecub.utils.DateUtil;
import com.bytecub.utils.JSONProvider;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 *  * ByteCub.cn.  * Copyright (c) 2020-2020 All Rights Reserved.  *   * @author bytecub@163.com songbin
 *  * @version Id: MQTTConsumeMonitor.java, v 0.1 2020-12-09  Exp $$  
 */
@Service
@Slf4j
public class DeviceUpConsume {
    @Autowired
    private DeviceMessageUpExecutor deviceMessageUpExecutor;

    @Async
    public void execute() {
        while (true) {
            try {
                DeviceUpMessageBo msg = DeviceUpMessageStorage.pop();
                deviceMessageUpExecutor.execute(msg);
            } catch (Exception e) {
                log.warn("内部队列消费异常", e);
                continue;
            }
        }
    }

}
